﻿myApp.controller('NewRentController', function ($scope, $http, DUMMY_DATA, $location, $rootScope) {

    $scope.$emit('newPageLoaded', {
        'title': 'New Property For Rent | ShiJie Property',
        'description': 'New Property For Rent. We Work Very Closely With Developers. Over 40 Years Experience. Discover The Best New Property For Rent Today!',
        'keywords': 'new property for rent, property for rent, for rent new property'
    });

    $scope.isAndroid = $rootScope.isAndroid;

    pageInit();

    $scope.sortOption = "Sorted by High to Low";

    $scope.property = {};
    $scope.property.transact = "R";

    var BASE_URL;
    if ($location.host() == "localhost") {
        BASE_URL = $location.protocol() + "://" + "localhost:" + $location.port();
    } else {
        BASE_URL = $location.protocol() + "://" + $location.host();
    }


    $scope.getShareURL = function (p) {
        //  return (BASE_URL + "/property/" + p.propertyid + "/S" + p.Zoning[0]);
        return (BASE_URL + "/property/" + p.propertyid + "/" + p.RentType);
    }

    $scope.getShareTitle = function (p) {
        return p.ShortHeading;
    }

    $scope.getShareDescription = function (p) {
        return p.LongHeading;
    }

    $scope.getShareImageURL = function (p) {
        return (p.PropertyURL || "https://c1.staticflickr.com/3/2280/32796837675_cd6b733c19_m.jpg");
    }




    $scope.paginate = function (value) {
        var begin, end, index;
        begin = ($scope.currentPage - 1) * $scope.numPerPage;
        end = begin + $scope.numPerPage;
        index = $scope.searchData.indexOf(value);
        return (begin <= index && index < end);
    };


    $scope.is10Selected = true;
    $scope.is25Selected = false;
    $scope.is50Selected = false;
    $scope.is100Selected = false;
    $scope.changePerPage = function (npp) {
        $scope.numPerPage = npp;
        switch (npp) {
            case 10:
                $scope.is10Selected = true;
                $scope.is25Selected = false;
                $scope.is50Selected = false;
                $scope.is100Selected = false;
                break;
            case 25:
                $scope.is10Selected = false;
                $scope.is25Selected = true;
                $scope.is50Selected = false;
                $scope.is100Selected = false;
                break;
            case 50:
                $scope.is10Selected = false;
                $scope.is25Selected = false;
                $scope.is50Selected = true;
                $scope.is100Selected = false;
                break;
            case 100:
                $scope.is10Selected = false;
                $scope.is25Selected = false;
                $scope.is50Selected = false;
                $scope.is100Selected = true;
                break;
        }
        $scope.totalItems = $scope.searchData.length;
        $scope.currentPage = 1;
        $scope.numPerPage = npp;

    }

    $scope.updateFilterOption = function (option, sortedChanged) {
        $scope.SortOptionChanged = sortedChanged;
        //$scope.$apply();
        console.log("HEY!" + option);
        switch (option) {
            case 0:
                $scope.sortOption = "Sorted by High to Low";
                $scope.sortKey = '-RentPrice';
                break;
            case 1:
                $scope.sortOption = "Sorted by Low to High";
                $scope.sortKey = 'RentPrice';
                break;
            case 2:
                $scope.sortOption = "Sorted by Area (A to Z)";
                $scope.sortKey = 'LongHeading';
                break;
            case 3:
                $scope.sortOption = "Sorted by Area (Z to A)";
                $scope.sortKey = '-LongHeading';
                break;
        }
    }

    $scope.go = function (key, value, transact) {
        console.log("TRANSACT: " + transact);
        console.log("CLICK!");
        value['transact'] = transact;
        var jsonObj = JSON.stringify(value);
        sessionStorage.setItem(key, jsonObj);
    }


    $scope.isPropertyTransactSale = function (obj) {
        return obj == 'S' ? true : false;
    }


    $scope.isEmpty = function (obj) {
        for (var i in obj) if (obj.hasOwnProperty(i)) return false;
        return true;
    };



    function pageInit() {
        if (DUMMY_DATA == true) {
            var dummyData = [{ "propertyid": "e7b9a8ba-51c0-4248-b3d3-2c40231bee5b", "Latitude": 5.313104, "Longitude": 100.462391, "road": "ASAS JAYA 3 LORONG", "location": "PERMATANG TINGGI", "state": "PENANG MAINLAND", "type": "2/S TER", "staffid": "b9fe0256-e070-473f-86f0-c6bb9bfa0531", "agentname": "OOI JYH SIANG", "mobile": "0172509595", "email": "jsooi@lskworld.com", "StaffPicURL": "https://farm9.staticflickr.com/8572/28152375032_d1abf44b2c_o.jpg", "LandSqrtFt": 1400.00, "BuildUp": 1400.00, "Project": null, "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 0, "Bathroom": 2, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Industrial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": null, "RIAmt": 1500.00, "RLAmt": null, "RentPrice": 1500.00, "UpdatedDate": "2016-11-09T14:19:19.867", "PropertyURL": null, "LongHeading": "DOUBLE STOREY TERRACE", "ShortHeading": "2/S TER", "RentType": "RI" }, { "propertyid": "d07f4588-9f0d-4015-98a7-3007284b52b2", "Latitude": 5.313105, "Longitude": 100.463428, "road": "ASAS JAYA 1 LORONG", "location": "PERMATANG TINGGI", "state": "PENANG MAINLAND", "type": "2/S TER", "staffid": "b9fe0256-e070-473f-86f0-c6bb9bfa0531", "agentname": "OOI JYH SIANG", "mobile": "0172509595", "email": "jsooi@lskworld.com", "StaffPicURL": "https://farm9.staticflickr.com/8572/28152375032_d1abf44b2c_o.jpg", "LandSqrtFt": 1400.00, "BuildUp": 1400.00, "Project": "KAWASAN PERINDUSTRIAN ASAS JAYA", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 0, "Bathroom": 0, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Industrial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": null, "RIAmt": 1500.00, "RLAmt": null, "RentPrice": 1500.00, "UpdatedDate": "2016-11-08T16:02:23.433", "PropertyURL": null, "LongHeading": "DOUBLE STOREY TERRACE, KAWASAN PERINDUSTRIAN ASAS JAYA", "ShortHeading": "2/S TER, KAWASAN PERINDUSTRIAN ASAS JAYA", "RentType": "RI" }, { "propertyid": "0e8f8eac-6394-4890-9d3a-4ea7b2cabb75", "Latitude": 5.418927, "Longitude": 100.389146, "road": "MAK MANDIN 5/1 LORONG", "location": "BUTTERWORTH", "state": "PENANG MAINLAND", "type": "1.5/S L/IND C", "staffid": "0e075adf-ee02-449d-9cf1-01344121df75", "agentname": "TEH KAI LOON", "mobile": "0124240123", "email": "keironteh@lskworld.com", "StaffPicURL": "https://farm8.staticflickr.com/7512/27584879561_d753d5db53_o.jpg", "LandSqrtFt": 2625.00, "BuildUp": 2625.00, "Project": "KAWASAN PERINDUSTRIAN MAK MANDIN", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 0, "Bathroom": 0, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Leasehold", "Facing": "", "Zoning": "Industrial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": null, "RIAmt": 2800.00, "RLAmt": null, "RentPrice": 2800.00, "UpdatedDate": "2016-11-11T16:26:01.473", "PropertyURL": "https://farm2.staticflickr.com/1491/25910705964_e7a2ab8469.jpg", "LongHeading": "ONE AND A HALF STOREY LIGHT INDUSTRI CORNER, KAWASAN PERINDUSTRIAN MAK MANDIN", "ShortHeading": "1.5/S L/IND C, KAWASAN PERINDUSTRIAN MAK MANDIN", "RentType": "RI" }, { "propertyid": "cbff4e35-0e97-4c5d-a2e9-5ba5ed786bcc", "Latitude": 5.417487, "Longitude": 100.331192, "road": "KIMBERLEY LEBUH", "location": "GEORGETOWN", "state": "PENANG ISLAND", "type": "2/S S/OFF (G/F)", "staffid": "783322d9-f9a4-43d7-89bf-b63812f49173", "agentname": "STEPHEN FOO", "mobile": "0124852981", "email": "stephenfoo@lskworld.com", "StaffPicURL": "https://farm4.staticflickr.com/3774/18727760624_3ff97e89e0_o.jpg", "LandSqrtFt": 2000.00, "BuildUp": 2000.00, "Project": "GEORGETOWN", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 1, "Bathroom": 1, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Commercial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": 7000.00, "RIAmt": null, "RLAmt": null, "RentPrice": 7000.00, "UpdatedDate": "2016-11-03T09:37:27.653", "PropertyURL": "https://farm6.staticflickr.com/5682/30111907054_46abf0b096.jpg", "LongHeading": "DOUBLE STOREY SHOP OFFICE (G/FLOOR), GEORGETOWN", "ShortHeading": "2/S S/OFF (G/F), GEORGETOWN", "RentType": "RC" }, { "propertyid": "20421060-7c91-4e6b-8064-6d9de7b99df4", "Latitude": 5.435061, "Longitude": 100.390129, "road": "ONG YI HOW JALAN", "location": "BUTTERWORTH", "state": "PENANG MAINLAND", "type": "3.5/S S/OFF (G/F)", "staffid": "1c3d41c2-a29a-44ce-8247-efd8cf67d75d", "agentname": "FOH CHOON SENG", "mobile": "0164402800", "email": "csfoh@lskworld.com", "StaffPicURL": "https://farm2.staticflickr.com/1617/26473478476_6aaedb7fbb_o.jpg", "LandSqrtFt": 1400.00, "BuildUp": 1400.00, "Project": "TAMAN PERINDUSTRIAN TERAS JAYA", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 0, "Bathroom": 1, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Commercial", "Furnished": "Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": 2500.00, "RIAmt": null, "RLAmt": null, "RentPrice": 2500.00, "UpdatedDate": "2016-11-07T15:03:55.077", "PropertyURL": null, "LongHeading": "THREE & A HALF STOREY SHOPOFFICE (G/FLOOR), TAMAN PERINDUSTRIAN TERAS JAYA", "ShortHeading": "3.5/S S/OFF (G/F), TAMAN PERINDUSTRIAN TERAS JAYA", "RentType": "RC" }, { "propertyid": "72bfced4-1309-4b22-9db3-91795fb96d2e", "Latitude": 5.318480, "Longitude": 100.452669, "road": "PERINDUSTRIAN BUKIT MINYAK JALAN", "location": "BUKIT MINYAK", "state": "PENANG MAINLAND", "type": "1.5/S DET", "staffid": "ff84c8dd-e80f-4956-b7ba-9d6d6c663bad", "agentname": "JT TAN", "mobile": "0123926682", "email": "jttan@lskworld.com", "StaffPicURL": "https://farm2.staticflickr.com/1550/25894540864_bd454b6be3_o.jpg", "LandSqrtFt": 174240.00, "BuildUp": 100000.00, "Project": "KAWASAN PERINDUSTRIAN BUKIT MINYAK", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 1, "Bathroom": 1, "FloorLoad": null, "Ceiling": "30 F", "BestBuy": 0, "Tenure": "Leasehold", "Facing": "", "Zoning": "Industrial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": null, "RIAmt": 90000.00, "RLAmt": null, "RentPrice": 90000.00, "UpdatedDate": "2016-11-09T12:08:09.37", "PropertyURL": "https://farm6.staticflickr.com/5707/30835591486_9d0dcbe260.jpg", "LongHeading": "ONE & A HALF STOREY DETACHED, KAWASAN PERINDUSTRIAN BUKIT MINYAK", "ShortHeading": "1.5/S DET, KAWASAN PERINDUSTRIAN BUKIT MINYAK", "RentType": "RI" }, { "propertyid": "b75ee57f-c487-4194-9dda-92e70d2aa571", "Latitude": 0.000000, "Longitude": 0.000000, "road": "BAYU MUTIARA 12 LORONG", "location": "BUKIT TENGAH", "state": "PENANG MAINLAND", "type": "2/S TER", "staffid": "01e38f67-39f1-435a-94a8-21847ea4afe0", "agentname": "ALVIN TEH", "mobile": "0182575717", "email": "tjt@lskworld.com", "StaffPicURL": "https://farm1.staticflickr.com/516/19162517368_b20643e0b1_o.jpg", "LandSqrtFt": 1540.00, "BuildUp": 1980.00, "Project": "TAMAN BAYU MUTIARA", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 4, "Bathroom": 3, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Residential", "Furnished": "Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": 1200.00, "RCAmt": null, "RIAmt": null, "RLAmt": null, "RentPrice": 1200.00, "UpdatedDate": "2016-11-03T14:29:57.373", "PropertyURL": null, "LongHeading": "DOUBLE STOREY TERRACE, TAMAN BAYU MUTIARA", "ShortHeading": "2/S TER, TAMAN BAYU MUTIARA", "RentType": "RR" }, { "propertyid": "38b66e99-0a9b-488f-b7a0-94879ed2439d", "Latitude": 5.400290, "Longitude": 100.322220, "road": "JELUTONG JALAN", "location": "JELUTONG", "state": "PENANG ISLAND", "type": "O/LOT (1/F)", "staffid": "91296169-8651-4a10-8ea5-34a1697f7d28", "agentname": "LONG SOO KEAT", "mobile": "0183987777", "email": "longsookeat@lskworld.com", "StaffPicURL": "https://farm2.staticflickr.com/1459/26499442055_39490f0b1c_o.jpg", "LandSqrtFt": 4200.00, "BuildUp": 4200.00, "Project": "JELUTONG", "ProjectRemark": null, "Developer": null, "PropertyDesc": "Nice renovation with air cond", "Room": 5, "Bathroom": 1, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "West", "Zoning": "Commercial", "Furnished": "Partially Furnished", "FurnishedRemark": null, "Renovated": "Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": 14000.00, "RIAmt": null, "RLAmt": null, "RentPrice": 14000.00, "UpdatedDate": "2016-11-08T18:35:45.327", "PropertyURL": "https://farm6.staticflickr.com/5806/30856690035_01b5fd57c0.jpg", "LongHeading": "OFFICE LOT (1ST FLOOR), JELUTONG", "ShortHeading": "O/LOT (1/F), JELUTONG", "RentType": "RC" }, { "propertyid": "8302bc66-4626-4b41-8fc1-9c8e3b2ea3eb", "Latitude": 5.370777, "Longitude": 100.443686, "road": "PERDA TIMUR 7 LORONG", "location": "BUKIT MERTAJAM", "state": "PENANG MAINLAND", "type": "1.5/S TER", "staffid": "3e6576a3-4e42-4623-baa2-86b20c546a33", "agentname": "KHOO WEI SHENG", "mobile": "0189654344", "email": "ws@lskworld.com", "StaffPicURL": "https://farm9.staticflickr.com/8139/29450596642_b1a89303d5_o.jpg", "LandSqrtFt": 1400.00, "BuildUp": 1400.00, "Project": "BANDAR PERDA", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 0, "Bathroom": 0, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Commercial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": 3500.00, "RIAmt": null, "RLAmt": null, "RentPrice": 3500.00, "UpdatedDate": "2016-11-14T16:21:19.12", "PropertyURL": "https://farm6.staticflickr.com/5827/22796556558_858f6bf6cc.jpg", "LongHeading": "ONE & A HALF STOREY TERRACE, BANDAR PERDA", "ShortHeading": "1.5/S TER, BANDAR PERDA", "RentType": "RC" }, { "propertyid": "b5e4d1ad-2b2e-42d4-816a-c6fbd4cd5670", "Latitude": 0.000000, "Longitude": 0.000000, "road": "BAYU MUTIARA 2 LORONG", "location": "BUKIT TENGAH", "state": "PENANG MAINLAND", "type": "2/S TER", "staffid": "01e38f67-39f1-435a-94a8-21847ea4afe0", "agentname": "ALVIN TEH", "mobile": "0182575717", "email": "tjt@lskworld.com", "StaffPicURL": "https://farm1.staticflickr.com/516/19162517368_b20643e0b1_o.jpg", "LandSqrtFt": 1400.00, "BuildUp": 1800.00, "Project": null, "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 4, "Bathroom": 3, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Residential", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": 1200.00, "RCAmt": null, "RIAmt": null, "RLAmt": null, "RentPrice": 1200.00, "UpdatedDate": "2016-11-07T18:31:06.567", "PropertyURL": null, "LongHeading": "DOUBLE STOREY TERRACE", "ShortHeading": "2/S TER", "RentType": "RR" }, { "propertyid": "0f39ffde-3b65-43fd-9acd-ef828146dda7", "Latitude": 0.000000, "Longitude": 0.000000, "road": "SERULING 5 LORONG", "location": "SUNGAI BAKAP", "state": "PENANG MAINLAND", "type": "1.5/S S/D", "staffid": "b56a6ecc-c278-4668-95d8-bfea3795848b", "agentname": "ALAN TAN", "mobile": "0178359233", "email": "alantankt@lskworld.com", "StaffPicURL": "https://farm9.staticflickr.com/8872/28220989626_70d17c335c_o.jpg", "LandSqrtFt": 6500.00, "BuildUp": 2550.00, "Project": "KAWASAN PERINDUSTRIAN VALDOR", "ProjectRemark": null, "Developer": null, "PropertyDesc": null, "Room": 0, "Bathroom": 2, "FloorLoad": null, "Ceiling": null, "BestBuy": 0, "Tenure": "Freehold", "Facing": "", "Zoning": "Industrial", "Furnished": "Not Furnished", "FurnishedRemark": null, "Renovated": "Not Renovated", "RenovatedRemark": null, "Condition": "", "RRAmt": null, "RCAmt": null, "RIAmt": 4500.00, "RLAmt": null, "RentPrice": 4500.00, "UpdatedDate": "2016-11-15T15:22:04.19", "PropertyURL": null, "LongHeading": "ONE & A HALF STOREY SEMI-DETACHED, KAWASAN PERINDUSTRIAN VALDOR", "ShortHeading": "1.5/S S/D, KAWASAN PERINDUSTRIAN VALDOR", "RentType": "RI" }];
            $scope.searchData = dummyData;
            console.log($scope.searchData.length);
            $scope.totalItems = $scope.searchData.length;
            $scope.currentPage = 1;
            $scope.numPerPage = 10;
        } else {
            $http.post('api/PropertySearch/GetAllNewRentProperty').success(function (data) {
                console.log("New Rent: " + JSON.stringify(data));
                $scope.searchData = data;
                $scope.totalItems = $scope.searchData.length;
                $scope.currentPage = 1;
                $scope.numPerPage = 10;
            });
        }
       

        
    }



});